package com.example.common.manager.server;

import com.example.common.manager.domain.StudentMsg;
import com.example.common.manager.mapper.DrawQuestionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@Service
public class DrawQuestionsServer {

    @Autowired
    DrawQuestionMapper mapper;

    public StudentMsg getStudent(String id) {
        List<StudentMsg> studentMsgList = new ArrayList<>();
        if ("2".equals(id)) {
            // 根据班级人数，随机生成一个数字

            studentMsgList = mapper.getStudentMsgByIdTow("2");
            System.out.println("111");
        }else if ("3".equals(id)) {
            studentMsgList = mapper.getStudentMsgByIdThree("3");
        }

        //跟据分数 排序 取出目前分数最低的同学 给其加分
        List<StudentMsg> list = studentMsgList.stream().sorted(Comparator.comparing(StudentMsg::getScore)).toList();
        //
        System.out.println();
        return list.get(0);

    }

    public void updateScore(StudentMsg studentMsg){
        int i = mapper.updateScore(studentMsg);
        System.out.println("更新 + " + i);
        System.out.println("更新成功！！！");
    }

    public void updateScoreThree(StudentMsg studentMsg){
        int i = mapper.updateScoreThree(studentMsg);
        System.out.println("更新 + " + i);
        System.out.println("更新成功！！！");
    }

}
